package com.vincent.kdp.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.vincent.baseapp.util.CommonUtil;
import com.vincent.kdp.R;
import com.vincent.kdp.adapter.RepairSpeedAdapter;
import com.vincent.kdp.bean.RepaireSpeedBean;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.repository.CheckGoodsRepository;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RepairGoodsSpeedActivity extends Activity {
    @Bind(R.id.back_img)
    ImageView backImg;
    @Bind(R.id.recyclerView_repair)
    RecyclerView mRecyclerViewRepair;
    @Bind(R.id.speed_all)
    RelativeLayout speed_all;

    private int id;
    private List<RepaireSpeedBean.DataBean> data=new ArrayList<>();
    private RepairSpeedAdapter adapter;
    private CheckGoodsRepository check=new CheckGoodsRepository();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_repair_goods_speed);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        id = getIntent().getIntExtra("record", -1);

        LinearLayoutManager manager=new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerViewRepair.setLayoutManager(manager);

        adapter=new RepairSpeedAdapter(this,data);
        mRecyclerViewRepair.setAdapter(adapter);

        getData(id);

    }

    private void getData(int id) {
        CommonUtil.showLoadingView(this);
        check.getSpeedList(id, new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                CommonUtil.dismissLoadingView(RepairGoodsSpeedActivity.this);
                RepaireSpeedBean bean= (RepaireSpeedBean) object;
                if(bean.getMsg().equals("请求成功")){
                    data.addAll(bean.getData());
                    adapter.notifyDataSetChanged();
                }else{
                    Toast.makeText(RepairGoodsSpeedActivity.this,"请求失败",Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFalse(String msg) {
                CommonUtil.dismissLoadingView(RepairGoodsSpeedActivity.this);
                Toast.makeText(RepairGoodsSpeedActivity.this,"请求失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @OnClick({R.id.back_img,R.id.speed_all})
    public void onClick() {
        finish();
        overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
    }
}
